package models

import "time"

// Wardrobe is the core entity tracked across lifecycle stages.
type Wardrobe struct {
	ID          int       `json:"id"`
	Code        string    `json:"code"`
	Name        string    `json:"name"`
	Status      string    `json:"status"`
	Location    string    `json:"location"`
	Specs       string    `json:"specs"`
	BuyPrice    float64   `json:"buy_price"`
	SalePrice   float64   `json:"sale_price"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

// Media represents image or video associated to a wardrobe at a stage.
type Media struct {
	ID          int       `json:"id"`
	WardrobeID  int       `json:"wardrobe_id"`
	URL         string    `json:"url"`
	MediaType   string    `json:"media_type"` // image | video
	Stage       string    `json:"stage"`      // disassembly | listing
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
}

// Expense is a line item recorded against a wardrobe.
type Expense struct {
	ID         int       `json:"id"`
	WardrobeID int       `json:"wardrobe_id"`
	Stage      string    `json:"stage"`    // disassembly | settlement
	Category   string    `json:"category"` // parking_fee | labor_fee | mileage_electricity | meals | platform_fee | payout_installer
	Amount     float64   `json:"amount"`
	Note       string    `json:"note"`
	CreatedAt  time.Time `json:"created_at"`
}

// InstallationInfo captures order and installation details.
type InstallationInfo struct {
	WardrobeID    int       `json:"wardrobe_id"`
	OrderTime     time.Time `json:"order_time"`
	CustomerName  string    `json:"customer_name"`
	CustomerPhone string    `json:"customer_phone"`
	Address       string    `json:"address"`
	HasElevator   bool      `json:"has_elevator"`
	InstallTime   time.Time `json:"install_time"`
	Notes         string    `json:"notes"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

// DetailedWardrobe aggregates the core record with related info for detail view.
type DetailedWardrobe struct {
	Wardrobe
	Media        []Media           `json:"media"`
	Expenses     []Expense         `json:"expenses"`
	Installation *InstallationInfo `json:"installation,omitempty"`
}

// DisassemblyCreateRequest is used to create a wardrobe in pending_disassembly status.
type DisassemblyCreateRequest struct {
	Code       string   `json:"code"`
	Name       string   `json:"name"`
	Location   string   `json:"location"`
	Specs      string   `json:"specs"`
	BuyPrice   float64  `json:"buy_price"`
	Images     []string `json:"images"`
	Videos     []string `json:"videos"`
	ParkingFee float64  `json:"parking_fee"`
	LaborFee   float64  `json:"labor_fee"`
}

type ListingUpdateRequest struct {
	SalePrice   float64  `json:"sale_price"`
	Description string   `json:"description"`
	Images      []string `json:"images"`
	Videos      []string `json:"videos"`
}

type InstallationUpsertRequest struct {
	OrderTimeISO   string `json:"order_time"`
	CustomerName   string `json:"customer_name"`
	CustomerPhone  string `json:"customer_phone"`
	Address        string `json:"address"`
	HasElevator    bool   `json:"has_elevator"`
	InstallTimeISO string `json:"install_time"`
	Notes          string `json:"notes"`
}

type SettlementRequest struct {
	LaborFee           float64 `json:"labor_fee"`
	ParkingFee         float64 `json:"parking_fee"`
	MileageElectricity float64 `json:"mileage_electricity_fee"`
	MealsFee           float64 `json:"meals_fee"`
	PlatformFee        float64 `json:"platform_fee"`
	PayoutInstaller    float64 `json:"payout_installer"`
}
